﻿(function () {
    'use strict';

    angular
        .module('app.login')
        .factory('UserContextData', UserContextData);

    UserContextData.$inject = ['$http','$q'];

    /* @ngInject */
    function UserContextData($http,$q) {
        var service = {

            GetUserLoginDetails: GetUserLoginDetails,
            AuthenticateUser: AuthenticateUser,
            GetUserQuestion: GetUserQuestion,
            UpdateUserPassword: UpdateUserPassword,
            ChangeUserPassword: ChangeUserPassword,
            AddNewUser:AddNewUser
        };

        return service;

        function GetUserLoginDetails() {
            return $http.get(apiLocation + 'User/3');            
        }

        function AuthenticateUser(Username, Password) {
            var data = "{'Username':'" + Username + "','Password':'" + Password + "'}";
            return $http.post(apiLocation + 'ValidateUserLogin',data);
        };

        function GetUserQuestion(Username) {
            var data = "{'Username':'" + Username + "'}";
            return $http.post(apiLocation + 'UserForgotPassword', data);
        };

        function UpdateUserPassword(Username, SecretAns, NewPassword) {
            var data = "{'Username':'" + Username + "','SecretAnswer':'" + SecretAns + "','NewPassword':'"+NewPassword+"'}";
            return $http.post(apiLocation + 'UserForgotPassword', data);
        };

        function ChangeUserPassword(Username, CurrentPassword, NewPassword) {
            var data = "{'Username':'" + Username + "','CurrentPassword':'" + CurrentPassword + "','NewPassword':'" + NewPassword + "'}";
            return $http.post(apiLocation + 'UserChangePassword', data);
        }

        function AddNewUser(UserName, Password, UserType, FirstName, LastName, SecretQn, SecretAns) {
            var data = "{'UserName':'" + UserName + "','Password':'" + Password + "','UserType':'" + UserType + "','FirstName':'" + FirstName + "','LastName':'" + LastName + "','SecretQn':'" + SecretQn + "','SecretAns':'" + SecretAns + "'}";
            return $http.post(apiLocation + 'NewUser', data);

        }
    }
}());
